package game;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Point2D;
import java.util.LinkedList;

public class ShootManager 
{
	
	public LinkedList<Shoot> enemyShoot = new LinkedList<Shoot>();
	public LinkedList<Shoot> iceShoot = new LinkedList<Shoot>();
	
	float time;

	private static ShootManager instance;
	
	public static ShootManager getInstance()
	{
		if(instance == null)
			instance = new ShootManager();
		
		return instance;
	}
	
	
	private ShootManager(){}
	
	public void UpdateShoot()
	{
		for (int h = 0; h < enemyShoot.size(); h++) 
			enemyShoot.get(h).update();
		
		for(int j = 0; j< iceShoot.size() ; j++)
			iceShoot.get(j).update();
		
		for (int h = 0; h < enemyShoot.size(); h++) 
		{
			if(enemyShoot.get(h).position.getX() > 3000 || enemyShoot.get(h).position.getX() <-2 || enemyShoot.get(h).position.getY()> 2000 || enemyShoot.get(h).position.getY() < -2)
			{
				enemyShoot.remove(h);
			}
			else
			{
				for(int x= 0; x < Mapa_01.getObstaculos().length; x++)
					if(enemyShoot.get(h).getRectangle().intersects(Mapa_01.getObstaculos()[x]))
					{
						enemyShoot.remove(h);
						break;
					}
			}		
		}
		for(int h = 0; h< iceShoot.size(); h++)
		{
			if(iceShoot.get(h).position.getX() > 3000 || iceShoot.get(h).position.getX() <-2 || iceShoot.get(h).position.getY()> 2000 || iceShoot.get(h).position.getY() < -2)
			{
				iceShoot.remove(h);
			}
			else
			{
				for(int x= 0; x < Mapa_01.getObstaculos().length; x++)
					if(iceShoot.get(h).getRectangle().intersects(Mapa_01.getObstaculos()[x]))
					{
						iceShoot.remove(h);
						break;
					}
			}		
		}
	}
	
	public void AddShoot(Point position, Point size, Point2D speed, int animationType, float dano)
	{
		if(new Rectangle(0,0,Game.screenWidth, Game.screenHeigth).contains(position))
			Audios.getInstance().Play(1);
		
		enemyShoot.add(new Shoot(position,size , speed, animationType, dano, true));
	}
	
	public void addIceShoot(Point position, Point size, Point2D speed, int animationType, float dano)
	{
		if(new Rectangle(0,0,Game.screenWidth, Game.screenHeigth).contains(position))
			Audios.getInstance().Play(1);
		
		iceShoot.add(new Shoot(position,size , speed, animationType, dano, true));
	}
	public void ClearTiros()
	{
		this.iceShoot.clear();
		this.enemyShoot.clear();
	}
	
	public void Draw(Graphics2D g2d)
	{
		for(int i =0; i < enemyShoot.size(); i++)
		{
			
			enemyShoot.get(i).draw(g2d);
		}
		for(int l = 0; l< iceShoot.size(); l++)
			iceShoot.get(l).draw(g2d);
	}
}
